package com.wenhai.concurrency.thread.pool;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName BlockingQueueTest
 * @Description
 * @Author 谢文海
 * @Date 2021/4/26 0:21
 * @Version 1.0
 **/
public class BlockingQueueTest {
    public static void main(String[] args) {
//        LinkedBlockingDeque<Runnable> queue = new LinkedBlockingDeque<>(2);
//        LinkedBlockingDeque<Runnable> queue = new LinkedBlockingDeque<>();
//        ArrayBlockingQueue queue = new ArrayBlockingQueue(2);
        SynchronousQueue queue = new SynchronousQueue();
        System.out.println(queue.size());
        ThreadPoolExecutor executor = new ThreadPoolExecutor(2, 3, 5, TimeUnit.SECONDS, queue);
        executor.execute(new MyRunnable());
        executor.execute(new MyRunnable());
        executor.execute(new MyRunnable());
//        executor.execute(new MyRunnable());
//        executor.execute(new MyRunnable());
//        executor.execute(new MyRunnable());
        System.out.println(executor.getPoolSize() + " " + queue.size());

    }
}
